﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Godot.core
{
    using ID = UInt32;

    public class RID
    {
        internal ID _id;
        internal RID_OwnerBase _owner;

        public RID()
        {
            _id = 0;
            _owner = null;
        }

        public ID get_id()
        {
            return _id;
        }
    }

    public class RID_OwnerBase
    {
        private static uint current_id = 0;

        internal void set_id(RID p_rid, ID p_id) 
        { 
            p_rid._id = p_id; 
        }

	    internal void set_ownage(RID p_rid) 
        { 
            p_rid._owner = (RID_OwnerBase)(this); 
        }

        public static void init_rid() 
        {
	        current_id = 1;
        }

        public ID new_ID() 
        {
	        ID id = (++current_id);
	        return id;
        }
    }

    public class RID_Owner<T> : RID_OwnerBase
    {
        internal Dictionary<ID, T> _id_map;

        public RID_Owner()
        {
            _id_map = new Dictionary<ID, T>();
        }

        public RID make_rid(T p_data)
        {
            ID id = new_ID();
            _id_map[id] = p_data;
            RID rid = new RID();
            set_id(rid, id);
            set_ownage(rid);

            return rid;
        }
    }
}
